package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class Test {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()) {
            String sql = "UPDATE teacher SET salary = salary-500 WHERE subject_id=(SELECT id FROM subject WHERE name='语文')";
            connection.setAutoCommit(false);
            Statement statement = connection.createStatement();
            int num = statement.executeUpdate(sql);
            System.out.println(num>0?"更新成功":"更新失败");
//            connection.commit();
//            System.out.println("调薪成功提交");
            connection.rollback();
            System.out.println("调薪回滚了");
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
